<template>
    <div style="
      display: flex;
      flex-direction: column;
      padding: 10px;
      align-items: flex-end;
    ">
        <!-- 弹窗start -->
        <el-dialog title="编辑序列号信息" width="20%" :visible.sync="editDislog" append-to-body="True">
            <el-form v-if="tableId == '17'" :rules="rules" ref="ruleForm" class="demo-ruleForm" label-width="100px"
                :model="editForm">
                <el-form-item label="软件类型:" prop="softwareType">
                    <el-select style="width:95%;" v-model="editForm.softwareType">
                        <el-option v-for="item in softwareTypeArray" :key="item.softKey" :label="item.softwareType"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="产品型号:" prop="productModel">
                    <el-select style="width:95%;" v-model="editForm.productModel">
                        <el-option v-for="item in productModelArray" :key="item.id" :label="item.modelName"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="客户信息:" prop="customerInfo">
                    <el-select style="width:95%;" v-model="editForm.customerInfo">
                        <el-option v-for="item in customerInfoArray" :key="item.id" :label="item.customerName"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="业务负责人:" prop="businessOwner">
                    <el-autocomplete style="width:95%;" v-model="editForm.businessOwner"
                        :fetch-suggestions="querySearchAsync" placeholder="格式:姓名-部门">
                    </el-autocomplete>
                </el-form-item>
                <el-form-item label="序列号:" prop="serialNumber">
                    <el-input style="width:95%;" type="text" autosize placeholder="请输入内容" v-model="editForm.serialNumber">
                    </el-input>
                </el-form-item>
                <!-- <div style="width:100%;display:flex;justify-content:flex-end;">
                    <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
                    <el-button>返回</el-button>
                </div> -->
            </el-form>
            <el-form v-if="tableId == '0' || tableId == '28'" :rules="rules" ref="ruleForm" class="demo-ruleForm"
                label-width="100px" :model="editForm">
                <el-form-item label="客户名称:" prop="customerName">
                    <el-autocomplete style="width:95%;" v-model="editForm.customerName" :disabled="editing"
                        :fetch-suggestions="querySearchAsync" placeholder="请输入客户名称" @select="handleSelect">
                    </el-autocomplete>
                </el-form-item>

                <el-form-item label="联系人姓名:" prop="personToContact">
                    <el-input style="width:95%;" type="text" autosize placeholder="请输入联系人姓名"
                        v-model="editForm.personToContact">
                    </el-input>
                </el-form-item>


                <el-form-item label="联系人职务:" prop="jobOfContact">
                    <el-input style="width:95%;" type="text" autosize placeholder="请输入联系人职务"
                        v-model="editForm.jobOfContact">
                    </el-input>
                </el-form-item>

                <el-form-item label="联系电话:" prop="phoneToContact">
                    <el-input style="width:95%;" type="text" autosize placeholder="请输入联系人电话"
                        v-model="editForm.phoneToContact">
                    </el-input>
                </el-form-item>

                <el-form-item label="电子邮箱:" prop="emailToContact">
                    <el-input style="width:95%;" type="text" autosize placeholder="请输入联系人电子邮箱"
                        v-model="editForm.emailToContact">
                    </el-input>
                </el-form-item>

                <el-form-item label="客户类型:" prop="customerType">
                    <el-select style="width:95%;" v-model="editForm.customerType" :disabled="editing">
                        <el-option v-for="item in customerTypeArray" :key="item.id" :label="item.content" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="企业规模:" prop="sizeOfEnterprise">
                    <el-select style="width:95%;" v-model="editForm.sizeOfEnterprise" :disabled="editing">
                        <el-option v-for="(item, index) in sizeOfEnterpriseArray" :key="index" :label="item" :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="业务方向:" prop="businessDirection">
                    <el-input style="width:95%;" type="text" autosize placeholder="业务方向:" :disabled="editing"
                        v-model="editForm.businessDirection">
                    </el-input>
                </el-form-item>
                <el-form-item label="通讯地址:" prop="addressToContact">
                    <el-input style="width:95%;" type="text" autosize placeholder="通讯地址:" :disabled="editing"
                        v-model="editForm.addressToContact">
                    </el-input>
                </el-form-item>
                <el-form-item label="备注:" prop="description">
                    <el-input style="width:95%;" type="text" autosize placeholder="备注:" v-model="editForm.description">
                    </el-input>
                </el-form-item>
            </el-form>
            <el-form v-if="tableId == '22'" :rules="rules" ref="ruleForm" class="demo-ruleForm" label-width="100px"
                :model="editForm">
                <el-form-item v-if="editing == true" label="有限期截止:" prop="endValidTime">
                    <el-date-picker :disabled="editForm.validForever" value-format="yyyyMMddHHmm"
                        v-model="editForm.endValidTime" align="right" type="date" placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item v-if="editing == true">
                    <el-checkbox v-model="editForm.validForever">终身授权</el-checkbox>
                </el-form-item>
                <div v-if="editing == false">
                    终止选中的注册信息?
                </div>
            </el-form>
            <el-form v-if="tableId == '26'" :rules="rules" ref="ruleForm" class="demo-ruleForm" label-width="100px"
                :model="editForm">
                <el-form-item label="软件名称:" prop="softwareType">
                    <el-input style="width:95%;" v-model="editForm.softwareType"></el-input>
                </el-form-item>
                <el-form-item label="软件代号:" prop="softKey">
                    <el-input style="width:95%;" v-model="editForm.softKey"></el-input>
                </el-form-item>
                <el-form-item label="软件描述:" prop="softwareDescribe">
                    <el-input :autosize="{ minRows: 2, maxRows: 4 }" type="textarea" style="width:95%;"
                        v-model="editForm.softwareDescribe"></el-input>
                </el-form-item>
            </el-form>
            <el-form v-if="tableId == '27'" :rules="rules" ref="ruleForm" class="demo-ruleForm" label-width="100px"
                :model="editForm">
                <el-form-item v-for="(item, index) in tableColumn" :key="index" :label="item.columnName + ':'">
                    <div style="display: flex;width:100%;">
                        <el-input style="width:85%;" v-model="editProductModel[item.prop]"></el-input>
                        <div style="margin-left: 10px;">{{ item.unit }}</div>
                    </div>

                </el-form-item>

            </el-form>
            <div style="width:100%;display:flex;justify-content:flex-end;">
                <el-button v-if="(tableId == '22' && editing == true) ||tableId == '0' || tableId == '28' || tableId == '17' || tableId == '27'" type="primary"
                    @click="submitForm('ruleForm')">保存</el-button>

                <el-button v-if="(tableId == '22' && editing == false) || tableId == '26'" type="primary" @click="submitUpdate">确认</el-button>
                <el-button @click="editDislog = false">返回</el-button>
            </div>
        </el-dialog>
        <!-- 弹窗end -->
        <el-dropdown placement="bottom" v-if="tableId == '17'" split-button @click="handleClick(1)"
            @command="handleClick(2)" style="width:170px;margin-bottom: 10px;">
            添加新的序列号
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>批量添加</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        <el-button v-if="tableId != '17' && tableId != '24' && tableId != '22'" style="width:170px;margin-bottom: 10px;"
            @click="addNewTryApplication">
            {{ interactButton }}
        </el-button>
        <div v-if="tableId == '22'" style="width: 100%;display:flex;justify-content: space-between;margin-bottom: 10px;">
            <div style="display: flex;align-items: center;width:1000px;">
                条件类型
                <el-select v-model="optionOfSearch" placeholder="请选择" style="margin-left: 10px;">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
                <el-input v-model="inputOfSearch" placeholder="输入关键字" style="width:250px;margin:0 10px;"></el-input>
                时间筛选
                <el-date-picker style="margin-left: 10px;" value-format="yyyyMMddHHmm" v-model="dateRangeForSearch" type="daterange" range-separator="至" start-placeholder="开始日期"
                    end-placeholder="结束日期">
                </el-date-picker>
            </div>
            <div style="width:500px;display:flex;justify-content:flex-end;">
                <el-button style="width:170px;" @click="getTableData()">
                    查询注册记录
                </el-button>
                <el-button style="width:170px;" >
                    重置筛选条件
                </el-button>
            </div>
        </div>
        <el-table :data="tableData" style="
        width: 100%;
        border-radius: 20px;
        padding:10px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
        overflow: auto;" :row-class-name="tableRowClassName" :header-cell-style="{
            background: '#316CFB', color: 'white'
        }">
            <el-table-column v-if="editBatch == true" :prop="item.prop" :label="item.columnName" v-for="item in tableColumn"
                :key="item.content">
                <template slot-scope="scope">
                    <el-select v-if="item.prop == 'softwareType'" v-model="scope.row.softwareType"
                        @input="updateItem(0, scope.row)">
                        <el-option v-for="item in softwareTypeArray" :key="item.softKey" :label="item.softwareType"
                            :value="item.softKey">
                        </el-option>
                    </el-select>
                    <div v-if="item.prop == 'id'">
                        {{ scope.row.id }}
                    </div>
                    <el-select v-if="item.prop == 'productModel'" v-model="scope.row.productModel"
                        @input="updateItem(0, scope.row)">
                        <el-option v-for="item in productModelArray" :key="item.id" :label="item.modelName"
                            :value="item.id">
                        </el-option>
                    </el-select>
                    <el-select v-if="item.prop == 'customerInfo'" v-model="scope.row.customerInfo"
                        @input="updateItem(0, scope.row)">
                        <el-option v-for="item in customerInfoArray" :key="item.id" :label="item.customerName"
                            :value="item.id">
                        </el-option>
                    </el-select>
                    <el-autocomplete style="width:300px;" v-if="item.prop == 'businessOwner'"
                        v-model="scope.row.businessOwner" :fetch-suggestions="querySearchAsync"
                        @input="updateItem(1, scope.row)" placeholder="格式:姓名-部门">
                        <el-checkbox-group v-model="scope.row.businessOwnerSAL" slot="append"
                            @input="updateItem(2, scope.row)">
                            <el-checkbox-button v-for="checkBox in checkboxGroup" :label="checkBox" :key="checkBox">{{
                                checkBox }}</el-checkbox-button>
                        </el-checkbox-group>
                    </el-autocomplete>
                    <el-input style="width:300px;" v-if="item.prop == 'serialNumber'" type="text" autosize
                        placeholder="请输入内容" v-model="scope.row.serialNumber" @input="updateItem(2, scope.row)">
                    </el-input>
                </template>
            </el-table-column>
            <el-table-column v-if="editBatch == false" :prop="item.prop" :label="item.columnName"
                v-for="item in tableColumn" :width="item.width != -1 ? item.width : null" :key="item.content">
            </el-table-column>
            <el-table-column label="操作" v-if="OperationArr.length > 0 && editBatch == false"
                :width="(tableId == '0') ? 300 : (tableId == '22') ? 150 : null">
                <template slot-scope="scope">
                    <el-button v-if="tableId == '0' || tableId == '17'" :type="opBar.operationType"
                        v-for="opBar in OperationArr" :key="opBar.id" @click="doOperation(scope.row, opBar.id)">{{
                            opBar.operationContent }}</el-button>
                    <el-link v-if="tableId == '22' || tableId == '26' || tableId == '28' || tableId == '27'"
                        :type="opBar.operationType" v-for="opBar in OperationArr" :key="opBar.id" style="margin-right:10px;"
                        @click="doOperation(scope.row, opBar.id)">{{ opBar.id == '40' || opBar.id == '42' || opBar.id ==
                            '44' || opBar.id ==
                            '46' ? (scope.row.valid
                                == 1 ? "锁定" : "解锁")
                            :
                            opBar.operationContent }}</el-link>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination @current-change="handleCurrentChange" :current-page="from" :page-sizes="[10]"
            style="margin-top:10px;" layout="total, sizes, prev, pager, next, jumper" :total="totalHits">
        </el-pagination>
        <div v-if="editBatch == true" style="width:100%;display:flex;justify-content: center;margin-top:10px;">
            <el-button type="primary" @click="submitMyShipment">添加</el-button>
            <el-button @click="initPage">返回</el-button>
        </div>
    </div>
</template>

<script>
import request from "../axios/request";
export default {
    data() {
        return {
            options:[
                {
                    label:"注册人员",
                    value:1
                },
                {
                    label:"客户名称",
                    value:2
                },
                {
                    label:"业务负责人",
                    value:3
                },
                {
                    label:"产品型号",
                    value:4
                },
                {
                    label:"序列号",
                    value:5
                }
            ],
            optionOfSearch:null,
            inputOfSearch:null,
            dateRangeForSearch:null,
            sizeOfEnterpriseArray: [
                "0 ~ 19 人",
                "20 ~ 99 人",
                "100 ~ 499 人",
                "500 ~ 999 人",
                "1000 ~ 9999 人",
                ">= 10000 人"
            ],
            editProductModel: {},
            from: 1,
            totalHits: null,
            editDislog: false,
            tableId: null,
            tableColumn: [],
            tableData: [],
            OperationArr: [],
            softwareTypeArray: [],
            productModelArray: [],
            customerInfoArray: [],
            checkboxGroup: ["同上"],
            editForm: {
                id: null,
                softwareType: null,
                productModel: null,
                customerInfo: null,
                businessOwner: null,
                serialNumber: null,
                endValidTime: null,
                validForever: false,
                softKey: null,
                softwareDescribe: null
            },
            interactButton: null,
            current: 0,
            size: 10,
            addNew: false,
            editBatch: false,
            editing: false,
            customerTypeArray: [{
                id: 0,
                content: "企业"
            }, {
                id: 1,
                content: "个人"
            }, {
                id: 2,
                content: "其他组织"
            }],
            rules: {
                softwareType: [
                    { required: true, message: '选择软件类型', trigger: 'change' }
                ],
                productModel: [
                    { required: true, message: '请选择产品型号', trigger: 'change' }
                ],
                customerInfo: [
                    { required: true, message: '请选择客户', trigger: 'change' }
                ],
                businessOwner: [
                    { required: true, message: '请输入负责人', trigger: 'blur' }
                ],
                serialNumber: [
                    { required: true, message: '请输入序列号', trigger: 'blur' }
                ],
                customerName: [
                    { required: true, message: '请输入客户名称', trigger: 'blur' }
                ],
                personToContact: [
                    { required: true, message: '请输入联系人名称', trigger: 'blur' }
                ],
                jobOfContact: [
                    { required: false, message: '请输入联系人职务', trigger: 'blur' }
                ],
                phoneToContact: [
                    { required: true, message: '请输入联系人电话', trigger: 'blur' }
                ],
                emailToContact: [
                    { required: true, message: '请输入电子邮箱', trigger: 'blur' }
                ],
                customerType: [
                    { required: true, message: '请选择客户类型', trigger: 'change' }
                ],
                sizeOfEnterprise: [
                    { required: true, message: '请选择企业规模', trigger: 'change' }
                ],
                businessDirection: [
                    { required: true, message: '请输入业务方向', trigger: 'blur' }
                ],
                addressToContact: [
                    { required: true, message: '请输入通讯地址', trigger: 'blur' }
                ],
                description: [
                    { required: false, message: '请输入备注', trigger: 'blur' }
                ]
            }
        }
    },
    async mounted() {
        this.tableId = String(this.$route.params.content);
        switch (this.tableId) {
            case "0":
                this.interactButton = "新增试用申请"
                break;
            case "26":
                this.interactButton = "添加新的软件"
                break;
            case "27":
                this.interactButton = "新增产品型号"
                break;
            case "28":
                this.interactButton = "新增客户信息"
                break;
            default:
                break;
        }
        this.initPage();
    },
    methods: {
        async submitUpdate() {
            let url = null
            let data = null
            let method = "PUT"
            switch (this.tableId) {
                case '26':
                    if (this.addNew == false) {
                        url = "/business/api/soft/updateSoftDetail"
                    } else {
                        url = "/business/api/soft/saveNew"
                        method = "POST"
                    }
                    data = this.editForm
                    break;
                case '22':
                    url = "/business/api/shipment/updateMachineStatus/" + this.editForm.id
                    break;


            }
            let resOfUpdateMachineStatus = await request({
                url: url,
                method: method,
                data: data
            });
            if (resOfUpdateMachineStatus.data.status == 200) {
                this.initPage()
            }
        },
        handleCurrentChange(val) {
            this.from = val;
            this.getTableData();
        },
        async handleSelect() {
            if (this.optionOfSearch == null) {
                 let resGettingCustomerInfoByName = await request({
                url: "/business/api/customer/getCustomerInfoByName/" + this.editForm.customerName,
                method: "GET"
            });
            this.editForm = resGettingCustomerInfoByName.data.data
            }else{

            }
           
        },
        addNewTryApplication() {
            this.editDislog = true
            this.addNew = true
            this.getSoftwareTypeArray()
            this.getProductModelArray()
            this.getCustomerInfoArray()
            this.editForm = {
                customerName: null,
                personToContact: null,
                jobOfContact: null,
                phoneToContact: null,
                emailToContact: null,
                customerType: null,
                sizeOfEnterprise: null,
                businessDirection: null,
                addressToContact: null,
                description: null
            }
        },
        async submitForm(formName) {
            if (this.tableId == '22') {
                let resOfUpdateEndValidTime = await request({
                    url: "/business/api/shipment/updateEndValidTime",
                    method: "PUT",
                    data: this.editForm
                });
                if (resOfUpdateEndValidTime.data.status == 200) {
                    this.initPage()
                }
                return;
            }
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let url = null;
                    let method = null;
                    let data = this.editForm;
                    if (this.tableId == '17') {
                        if (this.editing == false) {
                            console.log("新增");
                            url = "/business/api/shipment/addShipmentInfo";
                            method = "POST";
                        } else {
                            url = "/business/api/shipment/updateNotActiveShipment";
                            method = "PUT";
                        }
                    } else if (this.tableId == '28') {
                        if (this.addNew == false) {
                            url = "/business/api/customer/submitUpdateCustomerInfo";
                            method = "PUT";
                        } else {
                            url = "/business/api/customer/saveNewCustomerInfo";
                            method = "POST";
                        }

                    } else if (this.tableId == '27') {
                        if (this.addNew == false) {
                            url = "/business/api/productModel/submitUpdateProductModelInfo";
                            method = "PUT";
                        } else {
                            url = "/business/api/productModel/saveProductModelInfo";
                            method = "POST";
                        }
                        console.log(this.editProductModel);
                        data = this.editProductModel
                    } else {
                        if (this.editing == true) {
                            url = "/business/api/softOrder/UpdateSoftOrder";
                            method = "PUT";
                        } else {
                            url = "/business/api/softOrder/addSoftOrder";
                            method = "POST";
                        }
                    }
                    if (url != null) {
                        request({
                            url: url,
                            method: method,
                            data: data
                        }).then(res => {
                            if (res.status == 200) {
                                this.initPage()
                            }
                        });
                    }
                }
            });
        },
        async submitMyShipment() {
            let resOfSubmitMyShipment = await request({
                url: "/business/api/shipment/submitMyShipment",
                method: "POST"
            });
            if (resOfSubmitMyShipment.data.status == 200) {
                this.initPage();
            }
        },
        async updateItem(type, item) {
            if (type == 1) {
                item.businessOwnerSAL = false
            }
            await request({
                url: "/business/api/shipment",
                method: "PUT",
                data: item,
            });
        },
        tableRowClassName({ row, rowIndex }) {
            if (row.hasSync == 1) {
                return "syncing-row"
            }
            if (row.hasSync == 2) {
                return "justSync-row"
            }
            if (rowIndex % 2 == 0) {
                return "";
            } else {
                return "warning-row";
            }
        },
        async getTableData() {
            var serverUrl = null;
            var data = null;
            var requestMethod = "GET";
            switch (this.tableId) {
                case "17":
                    serverUrl = "/business/api/shipment/getNotActiveShipmentPage"
                    data = {
                        pageNo: this.from,
                        pageSize: 10
                    }
                    requestMethod = "POST"
                    break;
                case "0":
                    serverUrl = "/business/api/softOrder/getNotAuditingPage"
                    data = {
                        pageNo: this.from,
                        pageSize: 10
                    }
                    requestMethod = "POST"
                    break;
                case "22":
                    serverUrl = "/business/api/shipment/getRegisteredShipmentPage"
                    data = {
                        pageNo: this.from,
                        pageSize: 10,
                        option:this.optionOfSearch,
                        inputOfSearch:this.inputOfSearch,
                        dateRangeForSearch:this.dateRangeForSearch
                    }
                    requestMethod = "POST"
                    break;
                case "26":
                    serverUrl = "/business/api/soft/getAllSoftTypeDetail"
                    data = {
                        pageNo: this.from,
                        pageSize: 10
                    }
                    requestMethod = "POST"
                    break;
                case "28":
                    serverUrl = "/business/api/customer/getAllCustomersPage"
                    data = {
                        pageNo: this.from,
                        pageSize: 10
                    }
                    requestMethod = "POST"
                    break;
                case "24":
                    serverUrl = "/log/api/log/getLogPage"
                    data = {
                        pageNo: this.from,
                        pageSize: 10
                    }
                    requestMethod = "POST"
                    break;
                case "27":
                    serverUrl = "/business/api/productModel/getProductModelDetailPage"
                    data = {
                        pageNo: this.from,
                        pageSize: 10
                    }
                    requestMethod = "POST"
                    break;
            }
            let resOfGettingTableData = null
            if (serverUrl != null) {
                resOfGettingTableData = await request({
                    url: serverUrl,
                    method: requestMethod,
                    data: data
                });

            }
            if (data != null) {
                this.tableData = resOfGettingTableData.data.data.data
                this.totalHits = resOfGettingTableData.data.data.totalHit
                console.log(this.tableData);
            } else {
                this.tableData = resOfGettingTableData.data.data;
            }
        },
        async doOperation(item, opBarId) {
            switch (opBarId) {
                case 30:
                    this.operationToEdit(item);
                    break;
                case 31:
                    this.deleteNotActiveShipment(item);
                    break;
                case 33:
                    this.operationToEdit(item);
                    break;
                case 34:
                    this.approvedApply(item.id, 4);
                    break;
                case 35:
                    this.approvedApply(item.id, 3);
                    break;
                case 39:
                    this.editing=true
                    this.updateEndValidTime(item.id);
                    break;
                case 40:
                    this.updateMachineStatus(item.id);
                    break;
                case 41:
                    this.updateSoftWareDetail(item.id);
                    break;
                case 42:
                    this.updateSoftStatus(item.id);
                    break;
                case 43:
                    this.updateProductModelInfo(item)
                    break;
                case 44:
                    this.updateProductModelStatus(item.id)
                    break;
                case 45:
                    this.updateCustomerInfo(item)
                    break;
                case 46:
                    this.updateCustomerStatus(item.id)
                    break;
            }
        },
        updateProductModelInfo(item) {
            this.editDislog = true
            this.editProductModel = Object.assign({}, item)
            for (let key in item) {
                if (key == 'productModel' || key == 'valid' || key == 'id') {
                    continue
                } else {
                    this.editProductModel[key] = this.editProductModel[key].split(" ")[0]
                }
            }
        },
        async updateProductModelStatus(id) {
            let resOfUpdateProductModelStatus = await request({
                url: "/business/api/productModel/updateProductModelStatus/" + id,
                method: "PUT"
            });
            if (resOfUpdateProductModelStatus.data.status == 200) {
                this.initPage()
            }
        },
        async updateCustomerStatus(id) {
            let resOfUpdateSoftStatus = await request({
                url: "/business/api/customer/updateCustomerStatus/" + id,
                method: "PUT"
            });
            if (resOfUpdateSoftStatus.data.status == 200) {
                this.initPage()
            }
        },
        async updateCustomerInfo(item) {
            this.editDislog = true
            this.editForm = item
        },
        async updateSoftStatus(id) {
            let resOfUpdateSoftStatus = await request({
                url: "/business/api/soft/updateSoftStatus/" + id,
                method: "PUT"
            });
            if (resOfUpdateSoftStatus.data.status == 200) {
                this.initPage()
            }
        },
        async updateSoftWareDetail(id) {
            this.editDislog = true
            let resOfGetSoftDetailById = await request({
                url: "/business/api/soft/getSoftDetailById/" + id,
                method: "GET"
            });
            this.editForm = resOfGetSoftDetailById.data.data
        },
        updateMachineStatus(id) {
            this.editForm.id = id
            this.editDislog = true
            this.editing = false
        },
        async approvedApply(id, result) {
            let resOfSubmitResult = await request({
                url: "/business/api/softOrder/submitAuditResult",
                method: "POST",
                data: {
                    id: id,
                    result: result
                }
            });
            if (resOfSubmitResult.data.status == 200) {
                this.initPage()
            }
        },
        async deleteNotActiveShipment(item) {
            let resOfDeleteNotActiveShipment = await request({
                url: "/business/api/shipment/" + item.id,
                method: "DELETE"
            });
            if (resOfDeleteNotActiveShipment.data.status == 200) {
                this.initPage()
            }
        },
        operationToEdit(item) {
            this.editDislog = true
            this.editing = true
            this.editForm = item
            if (this.tableId != '17') {
                this.getSoftwareTypeArray()
                this.getProductModelArray()
                this.getCustomerInfoArray()
                return;
            }

        },
        updateEndValidTime(id) {
            this.editForm.id = id
            this.editDislog = true
            this.editing = true
        },
        async initPage() {
            this.tableData=[]
            this.tableColumn=[]
            this.forward = false
            this.dialogVisible = false;
            this.editBatch = false;
            this.editDislog = false;
            let resOfGettingTableColumns = null;
            if (this.tableId == '27') {
                resOfGettingTableColumns = await request({
                    url: "/sys/api/table/getColumnDynamically/" + this.tableId,
                    method: "GET",
                });
            } else {
                resOfGettingTableColumns = await request({
                    url: "/sys/api/table/getColumn/" + this.tableId,
                    method: "GET",
                });
            }
            this.tableColumn = resOfGettingTableColumns.data.data;
            // console.log(this.tableColumn);
            this.getTableData();
            this.getOperationArr();
        },
        async getOperationArr() {
            let resOfGettingOperationArr = await request({
                url: "/sys/api/operation/getTableOperations/" + this.tableId,
                method: "GET",
            });
            this.OperationArr = resOfGettingOperationArr.data.data;
        },
        handleClick(type) {
            switch (type) {
                case 1:
                    this.addANew()
                    break;
                case 2:
                    this.addBatchNew()
                    break;
                default:
                    break;
            }
        },
        async querySearchAsync(queryString, callBack) {
            let url = null
            switch (this.tableId) {
                case '0':
                case '28':
                    url = "/business/api/customer/getCustomerInfoInES?inputForSearch=" + queryString
                    break;
                default:
                    url = "/user/api/getUserInfo?inputForSearch=" + queryString
                    break;
            }
            let resOfGettingsuggestion = await request({
                url: url,
                method: "GET",
            });
            let resultArray = [];
            let result = resOfGettingsuggestion.data.data;
            if (result.length == 0) {
                resultArray.push({
                    value: "无匹配结果",
                });
            } else {
                //对获取的值进行遍历，调整数据结构，value
                for (let i = 0; i < result.length; i++) {
                    //需要注意的是回显的值必须是一个对象数组，且对象属性名称是 “value”，不然回显失败
                    resultArray.push({
                        value: result[i],
                    });
                }
            }
            callBack(resultArray);
        },
        addANew() {
            this.editDislog = true
            this.editing = false
            this.getSoftwareTypeArray()
            this.getProductModelArray()
            this.getCustomerInfoArray()
        },
        async getSoftwareTypeArray() {
            let resOfGetAllSoftType = await request({
                url: "/business/api/soft/getAllSoftType",
                method: "GET"
            });
            this.softwareTypeArray = resOfGetAllSoftType.data.data
            if (this.editBatch == true) {
                this.softwareTypeArray.push({
                    describe: null,
                    id: null,
                    name: "同上",
                    softKey: "SAL",
                    updateTime: null,
                    valid: null
                })
            }
            console.log(this.softwareTypeArray);
        },
        async getProductModelArray() {
            let resOfGetProductModelArray = await request({
                url: "/business/api/productModel/getAllProductModel",
                method: "GET"
            });
            this.productModelArray = resOfGetProductModelArray.data.data
            if (this.editBatch == true) {
                this.productModelArray.push({
                    id: -1,
                    modelName: "同上"
                })
            }
            console.log(this.productModelArray);
        },
        async getCustomerInfoArray() {
            let resOfGetCustomerInfoArray = await request({
                url: "/business/api/customer/getAllCustomers",
                method: "GET"
            });
            this.customerInfoArray = resOfGetCustomerInfoArray.data.data
            if (this.editBatch == true) {
                this.customerInfoArray.push({
                    contectInfo: null,
                    id: -1,
                    customerName: "同上",
                    personToContact: null,
                    updateTime: null,
                    valid: null
                })
            }
            console.log(this.customerInfoArray);
        },
        async addBatchNew() {
            this.OperationArr = []
            this.editBatch = true
            this.tableData = []
            let resOfGetUnSubmitShipment = await request({
                url: "/business/api/shipment/getUnSubmitShipment",
                method: "GET"
            });
            this.tableData = resOfGetUnSubmitShipment.data.data
            this.getSoftwareTypeArray()
            this.getProductModelArray()
            this.getCustomerInfoArray()
        }
    }
}
</script>

<style>
.el-table .warning-row {
    background-color: #F3F7FF;
}

.el-table .syncing-row {
    background-color: #FFE6E6;
}

.el-table .justSync-row {
    background-color: #E6FFF5;
}
</style>